<template>
  <div class="user">
    <div class="replayuser">
      <comment-user
        :parent="parent.parent"
        v-if="parent.parent"
        @click="replayClick($event)"
      ></comment-user>
      <div class="replayuserInfo" style="margin-bottom: 10px">
        <span style="font-size: 14px; color: #666666">{{
          parent.account.nickname
        }}</span>
        <i style="font-size: 14px; color: #999999">2020-10-09 10:56</i>
      </div>
      <p>{{ parent.content }}</p>
      <el-image
        v-for="v in parent.pics"
        :key="v.id"
        style="width: 100px; height: 100px"
        :src="$axios.defaults.baseURL + v.url"
        :preview-src-list="[$axios.defaults.baseURL + v.url]"
      >
      </el-image>
      <el-link
        type="primary"
        style="float: right"
        @click="replay(parent, $event)"
        >回复</el-link
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "commentUser",
  props: ["parent"],
  data() {
    return {};
  },
  methods: {
    replay(parent, $event) {
      console.log(parent);
      if (this.$store.state.user.userinfo.token) {
        this.$emit("click", $event);
        // document.querySelector(".user").scrollIntoView(true);
        // console.log(account.nickname, account.id); //需要传给其他组件
        this.$store.commit("user/setComment", {
          nickname: parent.account.nickname,
          id: parent.id,
        });
      } else {
        this.$store.commit("user/setURL", location.href);
        this.$router.push({ path: "/user/login" });
        this.$message.error("请先登录");
      }
    },
    replayClick($event) {
      this.$emit("click", $event);
    },
  },
  mounted() {},
  watch: {
    //  "$route.query.id"(){
    //    this.replay(parent)
    //  }
  },
};
</script>

<style lang="less" scoped>
.replayuser {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid black;
  padding: 20px 5px;
}
</style>